{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ab6c4330-dc94-464a-ad19-3ade87f33dac",
   "metadata": {},
   "outputs": [],
   "source": [
    "from decimal import Decimal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "609b3734-0e84-47c8-ba61-2d0bf87abd90",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = Decimal('1')\n",
    "b = Decimal('1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f1aebf3c-0a68-4aa8-b52b-52848fe0ba6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a == b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c428f9c7-7983-4a0c-abf2-b2b12254966b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a is b # 是否是同一对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "983266cc-1c09-4605-9ec1-4e5dab6f8173",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(139920038130864, 139920038130528)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id(a), id(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "09d40a65-4b4a-443e-91e6-14cc08d9555a",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = Decimal('1')\n",
    "b = a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "49b9ba26-08a0-4ec5-a9be-326b1b1e7ded",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b is a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "fbab5917-5bd1-41d0-9278-2c7f4e5f86ea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(139920038131648, 139920038131648)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id(a), id(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5361d5f3-c077-444a-93b6-1eca5ac7d7d3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "c4d856ff-2bbf-423b-95a0-27067bbd13d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "a = 0 + 1\n",
    "b = 2 - 1\n",
    "print(a is b)\n",
    "print(a == b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ffcdb5c9-5b8f-425b-967d-d0421c3af6dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "a = 'abc'\n",
    "b = 'ab' + 'c'\n",
    "print(a is b)\n",
    "print(a == b) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "76f4cec5-0856-47c2-90cf-76217193a261",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a == b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7dd07540-d0c6-4785-85c6-dc3c0afc4301",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a65fa2ec-be1c-4274-bf71-7ab34ac74a36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 10, 10]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[10] + [10] + [10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9ac0b53d-77e3-4bd4-bad2-4d4ec562e22c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['王五', '王五', '王五']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class Student:\n",
    "    def __init__(self, name, age):\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "\n",
    "s = [Student('张三', 19)] * 3\n",
    "\n",
    "s[0].name = '王五'\n",
    "\n",
    "[i.name for i in s]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9589fa00-a800-4ba5-a198-aec61e0632e3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "983d7776-faa4-46ae-8c48-a715584fc659",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[0, 1], [0, 1], [0, 1]]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [[0]] * 3\n",
    "s[0].append(1)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "60e7f9ff-eba4-4cdf-8a1b-2808301dba73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[0, 1], [0, 1], [0, 1]]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = [0]\n",
    "s = [x] + [x] + [x]\n",
    "s[0].append(1)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "fb64f52f-1422-40ef-a828-e3eba2f2f2af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[0, 1], [0], [0]]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = [[0]] + [[0]] + [[0]]\n",
    "s[0].append(1)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "443d24ce-c4dd-445e-9017-ac97e56fd5f3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "aada6391-4a5a-4681-a890-76b3baae7b7a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['王五', '张三', '张三']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "s = [Student('张三', 19)] + [Student('张三', 19)] + [Student('张三', 19)]\n",
    "\n",
    "s[0].name = '王五'\n",
    "\n",
    "[i.name for i in s]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
